package com.learn.security.core.validate.code;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 短信验证码
 */
public class ValidateCode implements Serializable {

    private static final long serialVersionUID = -7652855628938432829L;

    private String code;

    // 验证码生效的截止时间
    private LocalDateTime expireTime;

    /**
     * 验证码构造器
     * @param code 验证码字符
     * @param expireIn 验证码生效的截止时间
     */
    public ValidateCode(String code, int expireIn) {
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    /**
     * 验证码构造器
     * @param code 验证码字符
     * @param expireTime 验证码的有效时间（以秒为单位）
     */
    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    /**
     * 判断是否过期
     * @return true：过期
     */
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }
}
